/*
 * @Author: xuetao 3168581151@qq.com
 * @Date: 2025-02-11
 * @LastEditors: xuetao 3168581151@qq.com
 * @LastEditTime: 2025-02-11
 * @Description:
 */
import 'package:flutter/material.dart';

class BottomMenu extends StatelessWidget {
  final List<BottomMenuItem> menuItems; // 允许父组件传递自定义菜单项

  const BottomMenu({
    super.key,
    required this.menuItems,
  });

  // 显示底部菜单的静态方法
  static void showBottomMenu(BuildContext context, List<BottomMenuItem> items) {
    showModalBottomSheet(
      context: context,
      builder: (context) {
        return BottomMenu(menuItems: items);
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      height: menuItems.length * 67.0 + 80,
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: const BorderRadius.only(
          topLeft: Radius.circular(16.0),
          topRight: Radius.circular(16.0),
        ),
      ),
      child: Column(
        children: [
          // 遍历传递的菜单项并生成 ListTile
          ...menuItems.map((item) {
            return Column(
              children: [
                Padding(
                  padding:
                      const EdgeInsets.symmetric(vertical: 5.0), // 设置上下内边距来增加高度
                  child: ListTile(
                    title: Text(item.title,
                        textAlign: TextAlign.center,
                        style: TextStyle(fontSize: 20)),
                    onTap: item.onTap,
                  ),
                ),
                Divider(height: 1, color: Colors.grey[300]), // 水平分割线
              ],
            );
          }),
          Divider(
            height: 14,
            color: Colors.grey[300],
            thickness: 14.0,
          ), // 水平分割线
          Padding(
            padding: const EdgeInsets.symmetric(vertical: 5.0), // 设置上下内边距来增加高度
            child: ListTile(
              leading: null,
              title: Text(
                '取消',
                textAlign: TextAlign.center,
                style: TextStyle(fontSize: 20),
              ),
              onTap: () {
                Navigator.pop(context); // 关闭菜单
              },
            ),
          )
        ],
      ),
    );
  }
}

class BottomMenuItem {
  final String title;
  final IconData icon;
  final VoidCallback onTap;

  BottomMenuItem({
    required this.title,
    required this.icon,
    required this.onTap,
  });
}
